package com.coolgor.airvow.File.Web;

import com.coolgor.airvow.File.FileIO;
import com.coolgor.airvow.SQL.DataTable;


public class HTMLFunc {
	
	public static String readHTMLBody(String fileName,String encoding)
	{
		String res = "";
		
        res = readHTML(fileName,encoding);
        res = res.split("<body>")[1].split("</body>")[0];
     
		return res;
	}
	
	
	public static String readHTMLBody(String fileName)
	{
		return readHTMLBody(fileName,"utf-8");
	}
	
	
	public static String readHTML(String fileName)
	{
		return FileIO.read(fileName,"utf-8");
	}
	
	
	public static String readHTML(String fileName,String encoding)
	{
		return FileIO.read(fileName,encoding);
	}
	
	public static String DataTableToHtmlTable(DataTable dataTable)
	{
		if (null == dataTable) return null;
		if (dataTable.size()==0) return "<table></table>" ;
		StringBuffer string = new StringBuffer();
		string.append("<table>");		
		string.append("<thead>");
		string.append("<tr>");
		for (int i=1;i<=dataTable.getColumnNo();i++)
		{
			string.append("<th>");
			string.append(dataTable.getColumnName(i));
			string.append("</th>");
		}
		string.append("</tr>");
		string.append("</thead>");
		string.append("<tbody>");
		while(dataTable.next())
		{
			string.append("<tr>");
			for (int i=1;i<=dataTable.getColumnNo();i++)
			{
				string.append("<td>");
				string.append(dataTable.getString(i));
				string.append("</td>");
			}
			string.append("</tr>");			
		}
		string.append("</tbody>");
		string.append("</table>");
		return string.toString();
	}
	
}